var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var lessMiddleware = require('less-middleware');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var zy = require('./routes/zy');
var postRouter = require('./routes/post');
var post1Router = require('./routes/post1');
var post2Router = require('./routes/post2');
var getRouter = require('./routes/get');

var app = express();

// view engine setup  设置模板引擎
// app.set('view engine', 'ejs');//默认

// var ejs=require('ejs')设置ehs引擎
// app.engine(".html",ejs.__express);   // 双下划线
// app.set('view engine', 'html');//后缀换成html

// app.engine('html', require('express-art-template'));//不用改后缀

app.engine('art', require('express-art-template'));//art引擎



app.set('view engine', 'art');//换成art后缀 并且roures中index也加后缀
app.set('views', path.join(__dirname, 'views'));







app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(lessMiddleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/zy', zy);
app.use('/post', postRouter);
app.use('/get', getRouter);
app.use('/post1', post1Router);
app.use('/post2', post2Router);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
